<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('username',20)->nullable()->comment('用户名');
            $table->string('nickname',20)->nullable()->comment('用户昵称');
            $table->string('mobile',11)->unique()->nullable()->comment('手机号码');
            $table->string('email',50)->unique()->nullable()->comment('邮箱地址');
            $table->string('password')->notNull()->comment('密码');
            $table->tinyInteger('sex')->default(2)->comment('性别 0男 1女 2保密');
            $table->integer('score')->default(100)->comment('用户积分');
            $table->tinyInteger('role')->default(1)->comment('用户角色 1普通用户 2VIP 3系统管理员 100超级管理员');
            $table->tinyInteger('level')->default(1)->comment('用户身份等级 1码奴 2码徒 3码农 4码匠 5码师 6码神 7码圣');
            $table->string('avatar')->nullable()->comment('头像');
            $table->string('wechat')->nullable()->comment('微信openID');
            $table->string('remarks',100)->nullable()->comment('个人签名');
            $table->integer('inviter')->nullable()->comment('邀请人');
            $table->string('address',100)->nullable()->comment('通讯地址');
            $table->json('common')->nullable()->comment('共用字段');
            $table->dateTime('expired_at')->nullable()->comment(  'VIP过期时间');
            $table->tinyInteger('status')->default(1)->comment('用户状态 0待激活 1已激活（正常）2黑名单（密码多次错误）');
            $table->tinyInteger('is_delete')->default(0)->comment('是否注销 0正常状态 1已注销');
            $table->rememberToken();
            $table->timestamps();
        });

        Schema::create('password_reset_tokens', function (Blueprint $table) {
            $table->string('email')->primary();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });

        Schema::create('sessions', function (Blueprint $table) {
            $table->string('id')->primary();
            $table->foreignId('user_id')->nullable()->index();
            $table->string('ip_address', 45)->nullable();
            $table->text('user_agent')->nullable();
            $table->longText('payload');
            $table->integer('last_activity')->index();
        });

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('users');
        Schema::dropIfExists('password_reset_tokens');
        Schema::dropIfExists('sessions');
    }
};
